package com.homework;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;

public class homework3 {
    /*
    1.定义MainApp类，包含main()方法；
    2.在main()方法中，创建一个可以存储Student对象的集合对象；
    3.从控制台接收以下几个Student对象：
    学号	    姓名	   性别	   年龄	    身高
    it001	黄渤	    男		20		1.72
    it002	孙红雷	男		22		1.78
    it003	章子怡	女		18		1.64
    将每个对象添加到集合中(集合中学员学号唯一)；
    4.在MainApp中创建方法，可以打印所有学员信息：
    public static void printAll(ArrayList<Student>stuList){}
    5.在MainApp中创建方法，可以找出身高最高的学员，并打印：
    public static void findMaxHeight(ArrayList<Student>stuList){}
    6.在main()方法中，分别调用三个方法：打印所有学员，找出身高最高的学员；
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ArrayList<Student1> student1ArrayList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i + 1) + "个学员的学号");
            String id = input.next();
            System.out.println("请输入第" + (i + 1) + "个学员的姓名");
            String name = input.next();
            System.out.println("请输入第" + (i + 1) + "个学员的性别");
            String sex = input.next();
            System.out.println("请输入第" + (i + 1) + "个学员的年龄");
            Integer age = input.nextInt();
            System.out.println("请输入第" + (i + 1) + "个学员的身高");
            BigDecimal height = input.nextBigDecimal();
            Student1 student1 = new Student1(id,name,sex,age,height);
            student1ArrayList.add(student1);
        }
        printAll(student1ArrayList);
        findMaxHeight(student1ArrayList);
    }
    public static void printAll(ArrayList<Student1> stuList){
        for (Student1 student1 : stuList) {
            System.out.println(student1);
        }
    }
    public static void findMaxHeight(ArrayList<Student1> stuList){
        BigDecimal max = stuList.get(0).getHeight();
        for (Student1 student1 : stuList) {
            if (student1.getHeight().compareTo(max) == 1){
                max = student1.getHeight();
            }
        }
        System.out.println(max);
    }
}
class Student1{
    private String id;
    private String name;
    private String sex;
    private Integer age;
    private BigDecimal height;

    public Student1() {
    }

    public Student1(String id, String name, String sex, Integer age, BigDecimal height) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.height = height;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public BigDecimal getHeight() {
        return height;
    }

    public void setHeight(BigDecimal height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Student1{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student1 student1 = (Student1) o;
        return Objects.equals(id, student1.id) && Objects.equals(name, student1.name) && Objects.equals(sex, student1.sex) && Objects.equals(age, student1.age) && Objects.equals(height, student1.height);
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(id);
        result = 31 * result + Objects.hashCode(name);
        result = 31 * result + Objects.hashCode(sex);
        result = 31 * result + Objects.hashCode(age);
        result = 31 * result + Objects.hashCode(height);
        return result;
    }
}